$(function () {
    let state = localStorage.getItem("state");
    let dishesUrl = "/dishes?method=findAllDishes&sId=" + localStorage.getItem("sId");
    $('#dishesId').attr("target", dishesUrl);
    state == "1" && $.get(dishesUrl, function (data) {
        //首页请求
        $("#pageContent").html(data);
    });
    //侧边导航
    $('#indexMenu li').click(function () {
        let current = $(this);
        let target = current.find('a').attr("target");
        $.get(target, function (data) {
            $("#pageContent").html(data);
        });
        $('#indexMenu li').removeClass("active");
        current.addClass("active");
    });
    //顶部导航
    $('#navbar li').click(function () {
        let current = $(this);
        let target = current.find('a').attr("target");
        $.get(target, function (data) {
            $("#pageContent").html(data);
        })
    });
    //    根据state判断是否显示申请开店
    switch (state) {
        case "0":
            $(".waitErrInfo").show();
            setTimeout(() => {
                $(".waitErrInfo").hide();
            }, 5000);
            $(".navBarnner").css("display", "none");
            $("#applyStore").css("display","none");
            break;
        case "-1":
            $(".indeErrInfo").show();
            setTimeout(() => {
                $(".indeErrInfo").hide();
            }, 5000);
            $(".navBarnner").css("display", "none")
            break;
        case "2":
            $(".nopassErrInfo").show();
            setTimeout(() => {
                $(".nopassErrInfo").hide();
            }, 5000);
            $(".navBarnner").css("display", "none");
            $("#applyStore").css("display","none");
            break;
        case "3":
            $(".rejectErrInfo").show();
            setTimeout(() => {
                $(".rejectErrInfo").hide();
            }, 5000);
            $(".navBarnner").css("display", "none");
            break;
        default:
            $("#applyStore").css("display","none");
    }

    //退出登录
    $("#exit").on('click', (e) => {
        localStorage.removeItem("sId");
        localStorage.removeItem("state");
        window.location.href = "../html/login.html";
    })
});